home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
sendke1a
/
simkeys.bas
next >
Wrap
BASIC Source File
|
1999-03-10
|
5KB
|
143 lines
Attribute VB_Name = "simKeysModule"
Option Explicit
Type POINTAPI
x As Long
y As Long
End Type
Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const KEYEVENTF_KEYUP = &H2
Public Declare Sub keybd_event Lib "user32.dll" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
Public Declare Sub mouse_event Lib "user32.dll" _
(ByVal dwFlags As Long, _
ByVal dx As Long, _
ByVal dy As Long, _
ByVal cButtons As Long, _
ByVal dwExtraInfo As Long)
Public Declare Function OemKeyScan Lib "user32.dll" _
(ByVal wOemChar As Integer) As Long
Public Declare Function CharToOem Lib "user32.dll" _
Alias "CharToOemA" _
(ByVal lpszSrc As String, _
ByVal lpszDst As String) As Long
Public Declare Function VkKeyScan Lib "user32.dll" _
Alias "VkKeyScanA" _
(ByVal cChar As Byte) As Integer
Public Declare Function MapVirtualKey Lib "user32.dll" _
Alias "MapVirtualKeyA" _
(ByVal uCode As Long, _
ByVal uMapType As Long) As Long
Public Declare Function ClientToScreen Lib "user32.dll" _
(ByVal hwnd As Long, _
lpPoint As POINTAPI) As Long
Public Declare Function GetSystemMetrics Lib "user32.dll" _
(ByVal nIndex As Long) As Long
Public Declare Function GetCursorPos Lib "user32.dll" _
(lpPoint As POINTAPI) As Long
'Public Declare Function GetForegroundWindow Lib "user32.dll" () As Long
'Public Declare Function SetForegroundWindow Lib "user32.dll" _
(ByVal hwnd As Long) As Long
'Public Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Public Declare Sub Sleep Lib "kernel32.dll" _
(ByVal dwMilliSeconds As Long)
Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
' dwPlatformId defines:
Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2
Declare Function GetVersionEx Lib "kernel32.dll" _
Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
' Sends a single character using keybd_event
' Note that this function does not set shift state
' (By pressing down the shift key or setting the shift keys state)
' and it doesn't handle extended keys.
Public Sub SendAKey(ByVal vsChar As String)
Dim nVK As Integer
Dim nShift As Integer
Dim lOEMScan As Long
Dim lOEMShift As Long
Dim sOEMChar As String
' The VkKeyScan function translates a character to the corresponding
' virtual-key code and shift state for the current keyboard.
' If the function succeeds, the low-order byte of the return value
' contains the virtual-key code and the high-order byte contains
' the shift state.
nVK = VkKeyScan(CByte(Asc(vsChar)))
nShift = nVK \ (2 ^ 8)
nVK = nVK And &HFF
' The CharToOem function translates a string into the OEM-defined character set. '
' (OEM stands for original equipment manufacturer.)
' This function supersedes the AnsiToOem function.
sOEMChar = " " ' 2 character buffer
CharToOem Left$(vsChar, 1), sOEMChar
' the OemKeyScan function maps OEM ASCII codes 0 through 0x0FF
' into the OEM scan codes and shift states.
' The function provides information that allows a program to
' send OEM text to another program by simulating keyboard input.
' If the function succeeds, the low-order word of the return value
' contains the scan code of the given OEM character, and the
' high-order word contains the shift state.
lOEMScan = OemKeyScan(CInt(Asc(sOEMChar)))
lOEMShift = lOEMScan \ (2 ^ 8)
lOEMScan = lOEMScan And &HFF
' Send the key down
keybd_event CByte(nVK), CByte(lOEMScan), 0, 0
' Send the key up
keybd_event CByte(nVK), CByte(lOEMScan), KEYEVENTF_KEYUP, 0
End Sub
Public Sub MySendKeys(ByVal vsStr As String)
Dim x As Long
For x = 1 To Len(vsStr)
SendAKey Mid$(vsStr, x, 1)
Next
End Sub